#include "comm.hpp"

int main()
{
    int shmid = Getshm();   // 第二个进程只需要获取共享内存，不需要创建，也不需要删除
    //log(Debug, "create shm done");


    char* shmaddr = (char*)shmat(shmid, nullptr, 0);    // 共享内存挂接进程地址空间
    //log(Debug, "attach shm done, shmaddr: 0x%x", shmaddr);
    
    int fd = open(FIFO_FILE, O_WRONLY);
    if(fd < 0) exit(1);

    while(1)
    {
        cout << "Please Enter@ ";
        fgets(shmaddr, 4096, stdin);

        write(fd, "c", 1);      // 引入管道通信只是为了保证共享内存通信的同步性
    }

    shmdt(shmaddr);     // 去关联
    //log(Debug, "detach shm done, shmaddr: 0x%x", shmaddr);
 

    return 0;
}